home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / science / sm32a.zip / LIBRARY / LSOLVE.LI < prev    next >
Text File  |  1994-09-21  |  513b  |  10 lines

  1. # lsolve() solve linear equations
  2. # e.g. solve equations x+y-3=0 and x-y-1=0 for x and y
  3. # lsolve(x+y-3, x-y-1, x,y) gives [x=2,y=1]
  4.  
  5. lsolve(eq1_, eq2_, x_, y_) := if(order(eq1,x)==1 and order(eq1,y)==1 and order(eq2,x)==1 and order(eq2,y)==1,
  6.     block(dd:=coef(eq1,x,1)*coef(eq2,y,1)-coef(eq1,y,1)*coef(eq2,x,1),
  7.     [ x=(coef(eq1,y,1)*coef(coef(eq2,x,0),y,0)-coef(coef(eq1,x,0),y,0)*coef(eq2,y,1))/dd,
  8.       y=-(coef(eq1,x,1)*coef(coef(eq2,x,0),y,0)-coef(coef(eq1,x,0),y,0)*coef(eq2,x,1))/dd ]),
  9.       local(dd))
  10.